package com.jt.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author tang
 * @data 2021/10/11
 * @apiNode
 *
 * 构建一个Jedis数据源，基于此数据源可以从一个Jedis连接池获取链接
 */
public class JedisDataSource {

    private static final JedisPool jedisPool;
    private static final String host = "192.168.126.129";
    private static final int port = 6379;

    static {
        JedisPoolConfig Config = new JedisPoolConfig();
        Config.setMaxTotal(16);
        Config.setMaxIdle(60);
        jedisPool = new JedisPool(Config, host, port);
    }

    public static Jedis getConnection(){
        return jedisPool.getResource();
    }
}
